package Ioperation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class Addoperation implements Ioperation{
    @Override
    public void work(BookList books) {
        //输入添加书的属性
        //取出 书架的 书的 个数
        int ret = books.getBooksSize();

        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入要添加的书名:");
        String name = scanner.nextLine();
        //判断要添加的书 是否已经存在 如果存在就不添加了
        for (int i = 0; i < ret; i++) {
            if(name.equals(books.getBooks(i).getName())){
                System.out.println("已经有这本书了!");
                return;
            }
        }
        System.out.print("请输入书的作者:");
        String author = scanner.nextLine();
        System.out.print("请输入书的类型:");
        String type = scanner.nextLine();
        System.out.print("请输入书的价格:");
        int price = scanner.nextInt();
        //创建一个书，将属性添加进去
        Book book = new Book(name,author,price,type);

        books.setBooks(ret,book);
        //书的个数加 1
        books.setBooksSize(ret + 1);
    }
}
